Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Event Study - `i' not changing

    Hi,

    I am trying to run the code
    "forvalues i = 1(1)319 {
    reg return mkt_rtn if id == `i' & estimation_window == 1
    predict p if id == `i'
    predict std_err_residual, stdr replace SE_residual = std_err_residual if id == `i' //& event window == 1
    }"

    but I get no observations. I believe that the problem occurs with "id== `i' as I do not see variables changing in the dataset.


  • #2
    If you have cross-sectional data, then each id is an observation. You cannot run a regression using a single observation. But the error then should be "insufficient observations". Here, you are looping over consecutive ids numbered 1 to 319. If an id is missing, you will get a "no observations" error. Safer to collect the existing ids fulfilling your criterion:


    Code:
    qui levelsof id if estimation_window == 1 & id<=319, local(ids)
    foreach i of numlist `ids'{
        reg ...
    
    }
    Last edited by Andrew Musau; 19 Apr 2024, 04:47.

    Comment


    • #3
      To Andrew Musau 's excellent advice I will add:

      Inside the loop, you create variables p and std_err_residual, both using the -predict- command. But when you reach the second iteration of your loop, those variables will already exist, having been created in the first iteration. Stata will therefore refuse to carry out the -predict- command and will halt with an error message saying that variable p already exists.

      The solution to this is to add -drop p std_err_residual- at the end of the loop.

      Comment

      Working...
      X